define(['config/appregister',"business/engDepartment/services/httpService","jquery","business/engDepartment/directive/bigBanner","business/engDepartment/directive/smallBanner","business/services/filter"],function(app,httpServices){
    app.controller('engdepCtrl',function($scope,$http,$state,$interval){
    	$scope.isDetailPage = true;
        $scope.isMainpage = false;
    	
    	$scope.regionId = 0;
    	$scope.guildId = [];
    	$scope.scaleId = 0;
    	$scope.keyWord = "";
    	
    	$scope.tagChose1 = true;
    	$scope.tagChose2 = true;
    	$scope.tagChose3 = true;
    	//详情列表参数
        $scope.listParams = {
            regionId:"",
            guildIds:"",
            scaleId:"",
            keyWord:"",
            download: false,
            time: false,
            pageNo: 1,
            pageSize: 6,
            all: false,
            typeId: "",
            scId: "",
            dcId: "",
            keyWord:"",
            
            
        };
       $('.betterCompany').css({'left':$('.company-select').offset().left})
        //统计公司数，点评数，发布招聘数
        function getStatistics(){
        	var req = {
				type:'GET',
				uri:'getStatistics',
				data:{
					
				}
			};
			httpServices.companyHttpService(req).success(function(response){
				if(!response.data) return;
                $scope.$apply(function(){
					$scope.statistics = response.data;
                })
			}).error(function(response){
				console.log(response)
			})
        }
    	getStatistics();
    	
    	$scope.goCompany = function(companyId){
			var url = 'http://www.gongchengjie.cn/#/outIndexCtrl/homepageCtrl?companyId='+companyId;
			window.open(url,'_blank')
    	}
    	
    	//获取好评公司
    	function getPraiseCompany(){
    		var req = {
				type:'GET',
				uri:'getPraiseCompany',
				data:{
					count:10
				}
			};
			httpServices.companyHttpService(req).success(function(response){
				if(!response.data) return;
                $scope.$apply(function(){
					$scope.praiseCompany = response.data;
                })
			}).error(function(response){
				console.log(response)
			})
    	}
    	getPraiseCompany();
    	//分页获取公司列表
    	function getCompanyList(reg,gui,sca,keyw,e){
    		/*if(gui == []){
    			var guilds = "";
    		}else{
    			var guilds = [];
    			var obj = {};
    			for(var i = 0;i<gui.length;i++){
    				if(!obj[gui[i]]){
    					guilds.push(gui[i]);
    					obj[gui[i]] = 1;
    				}
    			}
    			guilds = guilds.join(",");
    		}*/
    		var req = {
				type:'GET',
				uri:'getCompanyList',
				data:{
					pageNo:$scope.listParams.pageNo,
					pageSize:$scope.listParams.pageSize,
					regionId:reg,
					guildIds:gui,
					scaleId:sca,
					keyWord:keyw,
					all:false
				}
			};
			httpServices.companyHttpService(req).success(function(response){
				if(!response.data) return;
                $scope.$apply(function(){
                    $scope.companyList = response.data.list;    
                    $scope.totalItem = response.data.Pagination.totalCount;
                    getListModel()
                })
			}).error(function(response){
				console.log(response)
			})
    	}
    	getCompanyList(0,"",0,"");
    	//有条件获取公司列表
    	$scope.getSomeCompany = function(reg,gui,sca,keyw,e){
    		if(e){
    			var os = $(e.target);
    			/*if(os.parent().hasClass('guild')){//判断是否多选
    				if(os.hasClass('guildone')){
    					os.addClass('active').siblings().removeClass();
    				}else{
    					os.parent().find('span').eq(0).removeClass('active')
    					os.addClass('active');
    				}
    			}else{//单选
    				os.addClass('active').siblings().removeClass('active');
    			}*/
				os.addClass('active').siblings().removeClass('active');
    		}
    		if(reg == ""){
    			$scope.regionId = $scope.regionId
    		}else{
    			$scope.regionId = reg;
    		}
    		/*if(gui == ""){
				$scope.guildId = [];
			}else{
				if($scope.guildId == gui){
					$scope.guildId = $scope.guildId;
				}else{
					$scope.guildId.push(gui)
				}
			}*/
			if(gui == ""){
				$scope.guildId = $scope.guildId;
			}else if(gui == 0){
				$scope.guildId = "";
			}else{
				$scope.guildId = gui;
			}

    		if(sca == ""){
    			$scope.scaleId = $scope.scaleId
    		}else{
    			$scope.scaleId = sca;
    		}
    		if(keyw == ""){
    			$scope.keyWord = "";
    		}else{
    			$scope.keyWord = keyw;
    		}
    		getCompanyList($scope.regionId,$scope.guildId,$scope.scaleId,$scope.keyWord,e)
   	 	}
    	//获取公司地点
    	function getPlace(){
    		var req = {
				type:'GET',
				uri:'getHotRegionList',
				data:{
					
				}
			};
			httpServices.placeHttpService(req).success(function(data){
				if(!data.data) return;
                $scope.$apply(function(){
					$scope.placeList = data.data.splice(0,14);
                })
			}).error(function(response){
				console.log(response)
			})
    	}
    	getPlace();
    	
    	//获取行业领域
    	function getGuildList(){
    		var req = {
				type:'GET',
				uri:'getGuildList',
				data:{
					
				}
			};
			httpServices.placeHttpService(req).success(function(response){
				if(!response.data) return;
                $scope.$apply(function(){
                	$scope.guildList = response.data;
					//$scope.guildList.length = 8;
					$scope.guildListAll = response.data;
                })
			}).error(function(response){
				console.log(response)
			})
    	}
    	getGuildList();
    	//获取企业规模
    	function getScaleList(){
    		var req = {
				type:'GET',
				uri:'getScaleList',
				data:{
					
				}
			};
			httpServices.placeHttpService(req).success(function(response){
				if(!response.data) return;
                $scope.$apply(function(){
                    $scope.scaleList = response.data;
					//$scope.scaleList.length = 8;
					$scope.scaleListAll = response.data;
                })
			}).error(function(response){
				console.log(response)
			})
    	}
    	getScaleList();
    	//获取公司动态
    	function getCompanyDynamicList(){
    		var req = {
				type:'GET',
				uri:'getCompanyDynamicList',
				data:{
					searchType:1,
					pageNo:1,
					pageSize:5
				}
			};
			httpServices.companyHttpService(req).success(function(response){
				if(!response.data) return;
                $scope.$apply(function(){
                    $scope.dynamic = response.data.list;
                })
			}).error(function(response){
				console.log(response)
			})
    	}
    	getCompanyDynamicList();
    	//更多
    	$scope.moreTag1 = function(){
    		if($scope.tagChose1){
				function getPlace1(){
					var req = {
						type:'GET',
						uri:'getHotRegionList',
						data:{

						}
					};
					httpServices.placeHttpService(req).success(function(data){
						if(!data.data) return;
						$scope.$apply(function(){
							$scope.placeList = data.data;
						})
					}).error(function(response){
						console.log(response)
					});
				}
				getPlace1();
    		}else{
    			$scope.placeList = $scope.placeList.slice(0,14)
    		}
    		$scope.tagChose1 = !$scope.tagChose1;
    	}
    	/*$scope.moreTag2 = function(){
    		if($scope.tagChose2){
    			$scope.guildList = $scope.guildListAll;
    		}else{
    			$scope.guildList = $scope.guildList.slice(0,8)
    		}
    		$scope.tagChose2 = !$scope.tagChose2;
    	}
    	$scope.moreTag3 = function(){
    		if($scope.tagChose3){
    			$scope.scaleList = $scope.scaleListAll
    		}else{
    			$scope.scaleList = $scope.scaleList.slice(0,8)
    		}
    		$scope.tagChose3 = !$scope.tagChose3;
    	}*/

    	
    	//分页
    	function getListModel() {
			$scope.paginationConf = {
				currentPage: $scope.listParams.pageNo,
				totalItems: $scope.totalItem,
				//每页预览条数
				itemsPerPage: $scope.listParams.pageSize,
				//分页总数
				numberOfPages: Math.ceil($scope.totalItem / $scope.listParams.pageSize),
				// 实际分页长度
				pagesLength: 5,
				perPageOptions: [10, 20, 30, 40, 50],
				onChange: function(currentPage) {
					if(currentPage) {
						$scope.paginationConf.currentPage = currentPage;
					}
					$scope.list = [];
					$scope.listParams.pageNo = $scope.paginationConf.currentPage;
					getCompanyList($scope.regionId,$scope.guildId,$scope.scaleId,$scope.keyWord)
				}
			};
		}
    	
    	
    	//好评公司
    	var index = 0;
    	$scope.smallMove = function(e,dir){
    		var oUl = $(e.target).parent().find('ul');
    		var len = oUl.find('li').length;
    		oUl.width(120*len);
    		index += dir;
    		if(index <= 4-len){
    			index = 4-len;
    		}else if(index >= 0){
    			index = 0;
    		}
    		oUl.stop().animate({left:index*120+"px"});
    	}
    	
    	
    	//最新点评
    	function getNewComment(){
    		var req = {
				type:'GET',
				uri:'getRecentComment',
				data:{
					count:5
				}
			};
			httpServices.commentHttpService(req).success(function(response){
				if(!response.data) return;
                $scope.$apply(function(){
                    $scope.commentList = response.data;
                })
			}).error(function(response){
				console.log(response)
			})
    	}
    	getNewComment();
    	
    	
    	//跳转各个详情页
    	$scope.goto = function(item){
    		if(item.cdType == 1){
    			$state.go('zpdetailCtrl',{'companyId':item.userId,'jobId':item.fkId});
    		}else if(item.cdType == 2){
    			$state.go('outIndexCtrl.bwDetailCtrl',{'companyId':item.userId,'outBlogId':item.fkId});
    		}else if(item.cdType == 3){
    			$state.go('eng.vedioDetails',{'courseId':item.fkId});
    		}
		}
		//最新点评跳转
		$scope.goMainPage = function(item){
			var url;
			url = 'http://www.gongchengjie.cn/#/othersMainPage?userId='+item.userId;
			window.open(url,'_blank')
		}
		$scope.goComPage = function(item){
			var url;
			url = 'http://www.gongchengjie.cn/#/outIndexCtrl/homepageCtrl?companyId='+item.byUserId;
			window.open(url,'_blank')
		}
	})
  })